package com.edu.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.edu.entity.SysRole;
import com.edu.entity.SysUserInfo;
import com.edu.user.mapper.SysRoleMapper;
import com.edu.user.service.ISysRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.edu.vo.PageResultVO;
import com.edu.vo.Result;
import org.apache.catalina.core.FrameworkListener;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 后端角色表 服务实现类
 * </p>
 *
 * @author jr
 * @since 2021-04-15
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Override
    public Result queryRole() {

        Wrapper wrapper = new QueryWrapper();
        List list = this.baseMapper.selectList(wrapper);

        return new Result(true,0,"查询成功",list) ;
    }

    @Override
    public PageResultVO queryListByPage(Integer currentPage, Integer pageSize, String name) {

        //设置分页信息
        IPage<SysRole> iPage = new Page(currentPage,pageSize);

        //条件构造器
        QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
        if (!StringUtils.isEmpty(name)) {
            queryWrapper.like("role_name", name);
        }

        IPage pageInfo = this.baseMapper.selectPage(iPage, queryWrapper);


        return new PageResultVO<SysUserInfo>(0,"用户信息查询",pageInfo.getTotal(),pageInfo.getRecords());

    }
}
